Add offering preset variables for Network and VPC Quota tariffs#11810
Add offering preset variables for Network and VPC Quota tariffs#11810hsato03 wants to merge 2 commits intoapache:mainfrom
Network and VPC Quota tariffs#11810Conversation
|
@blueorangutan package |
|
@hsato03 a [SL] Jenkins job has been kicked to build packages. It will be bundled with KVM, XenServer and VMware SystemVM templates. I'll keep you posted as I make progress. |
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #11810 +/- ##
=========================================
Coverage 17.84% 17.85%
- Complexity 15983 15985 +2
=========================================
Files 5929 5929
Lines 531084 531116 +32
Branches 64914 64914
=========================================
+ Hits 94795 94810 +15
- Misses 425675 425691 +16
- Partials 10614 10615 +1
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
|
Packaging result [SF]: ✔️ el8 ✔️ el9 ✔️ el10 ✔️ debian ✔️ suse15. SL-JID 15349 |
|
This pull request has merge conflicts. Dear author, please fix the conflicts and sync your branch with the base branch. |
|
@blueorangutan package |
|
@DaanHoogland a [SL] Jenkins job has been kicked to build packages. It will be bundled with no SystemVM templates. I'll keep you posted as I make progress. |
|
Packaging result [SF]: ✔️ el8 ✔️ el9 ✔️ el10 ✔️ debian ✔️ suse15. SL-JID 16429 |
|
@blueorangutan test keepEnv |
|
@DaanHoogland a [SL] Trillian-Jenkins test job (ol8 mgmt + kvm-ol8) has been kicked to run smoke tests |
|
[SF] Trillian test result (tid-15218)
|
There was a problem hiding this comment.
Pull request overview
This PR adds offering preset variables for Network and VPC quota tariffs, enabling users to create activation rules based on the network offering and VPC offering properties.
Changes:
- Added
networkOfferingandvpcOfferingpreset variables to theValueclass with appropriate getters/setters - Implemented helper methods to retrieve network and VPC offering information
- Relocated VPC offering DAO beans to the common Spring context for usage module access
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| PresetVariableHelper.java | Added getPresetVariableValueNetworkOffering and getPresetVariableValueVpcOffering methods to populate offering information; updated load methods to set the new fields |
| Value.java | Added networkOffering and vpcOffering fields with @PresetVariableDefinition annotations and corresponding getters/setters |
| PresetVariableHelperTest.java | Added unit tests for the new getPresetVariableValueNetworkOffering and getPresetVariableValueVpcOffering methods; added VpcOfferingDao mock |
| spring-engine-schema-core-daos-context.xml | Removed vpcOfferingDaoImpl and vpcOfferingDetailsDaoImpl bean definitions |
| spring-engine-schema-core-common-daos-between-management-and-usage-context.xml | Added vpcOfferingDaoImpl and vpcOfferingDetailsDaoImpl bean definitions to make them accessible in the usage context |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| value.setName(network.getName()); | ||
| value.setState(usageRecord.getState()); | ||
|
|
||
| value.setNetworkOffering(getPresetVariableValueNetworkOffering(network.getNetworkOfferingId())); |
There was a problem hiding this comment.
The new networkOffering field is being set in loadPresetVariableValueForNetwork, but there are no tests verifying this integration. Similar methods like loadPresetVariableValueForVolume and loadPresetVariableValueForBackup have comprehensive tests that verify all fields are properly set. Consider adding a test similar to loadPresetVariableValueForBackupTestRecordIsBackupSetAllFields that verifies the networkOffering field is correctly populated.
|
|
||
| value.setId(vpc.getUuid()); | ||
| value.setName(vpc.getName()); | ||
| value.setVpcOffering(getPresetVariableValueVpcOffering(vpc.getVpcOfferingId())); |
There was a problem hiding this comment.
The new vpcOffering field is being set in loadPresetVariableValueForVpc, but there are no tests verifying this integration. Similar methods like loadPresetVariableValueForVolume and loadPresetVariableValueForBackup have comprehensive tests that verify all fields are properly set. Consider adding a test similar to loadPresetVariableValueForBackupTestRecordIsBackupSetAllFields that verifies the vpcOffering field is correctly populated.
| value.setVpcOffering(getPresetVariableValueVpcOffering(vpc.getVpcOfferingId())); | ||
| } | ||
|
|
||
| protected GenericPresetVariable getPresetVariableValueVpcOffering(long vpcOfferingId) { |
There was a problem hiding this comment.
The parameter type should be Long instead of long to maintain consistency with similar methods in this class. Other methods like getPresetVariableValueNetworkOffering, getPresetVariableZone, and getPresetVariableValueTemplate all use Long as the parameter type.
| protected GenericPresetVariable getPresetVariableValueVpcOffering(long vpcOfferingId) { | |
| protected GenericPresetVariable getPresetVariableValueVpcOffering(Long vpcOfferingId) { |
|
@hsato03 , I feel a bit out of my depth on these preset variables and they only appear once in the documentation when it comes to storage; i.e. https://docs.cloudstack.apache.org/en/4.22.0.0/adminguide/storage.html#direct-resources-to-a-specific-secondary-storage. Is there some wiki page I can read to be able to concoct sensible tests for this? @winterhazel , will you review? |
@DaanHoogland yes, I should be able to review and test this one by the end of the week.
The Quota documentation needs some updating on how to use the activation rules and preset variables. There is no wiki on how to use them at the moment. We hope to address it in version 23/24 along with the pending code changes. Here's a basic guide on how to test the changes in this PR:
After the Usage job finishes generating all usage records, Quota will process them and charge credits from users based on the tariffs. You can follow Usage's logs during the job's execution to see which values are being charged for that execution, debug it to see which values are being injected as preset variables (I usually place my breakpoint in org.apache.cloudstack.quota.QuotaManagerImpl#injectPresetVariablesIntoJsInterpreter), and see the new balances in the Quota summary page. The idea for debugging other PRs that add preset variables is the same. |
|
While testing this, I found that preset variables are not being injected correctly into the JS interpreter anymore, which prevents this change from working as expected. #12515 needs to be merged first. |
Description
This PR adds two new preset variables for
NetworkandVPCusage type Quota tariffs.For
Networktariffs, the variablesvalue.networkOffering.idandvalue.networkOffering.namehave been created. ForVPCtariffs, the variablesvalue.vpcOffering.idandvalue.vpcOffering.namehave been added.They represent the resource's offering ID and name, respectively.
Types of changes
Feature/Enhancement Scale or Bug Severity
Feature/Enhancement Scale
Bug Severity
Screenshots (if appropriate):
How Has This Been Tested?
I created an isolated network and a VPC with the following offerings.
Then, I created a
Networktariff (offering-test-network) with the following activation rule.Next, I created a
VPCtariff (offering-test-vpc) with the following activation rule.I called the
quotaUpdateAPI and verified that the value 300 was returned by theoffering-test-networkactivation rule, whileoffering-test-vpcreturned 500.How did you try to break this feature and the system with this change?